from rest_framework import serializers
from goods.models import GoodsChannel, GoodsChannelGroup


class GoodsChannelSerializer(serializers.ModelSerializer):
    """ 商品频道 模型类序列化器 """
    category = serializers.StringRelatedField(read_only=True)
    category_id = serializers.IntegerField()
    group = serializers.StringRelatedField(read_only=True)
    group_id = serializers.IntegerField()

    class Meta:
        model = GoodsChannel
        fields = ["id", "category", "category_id", "group", "group_id", "sequence", "url"]


class GoodsChannelGroupSerializer(serializers.ModelSerializer):
    """商品频道分组 模型类序列化器"""

    class Meta:
        model = GoodsChannelGroup
        fields = ["id", "name"]
